﻿/// <reference path="../typings/jquery/jquery.d.ts" />
/// <reference path="../typings/windjs/windjs.d.ts" />
// Module
module Soict
{
	export interface Event
	{
		(param?: any): void;
	}

	export class Board
	{

		private board: JQuery ;
		private tags: JQuery[] = [];
		private tagids=[];
		private classname = "boarditem";

		public onTagRemove(param?:any) { }

		public init(id: string)
		{
			this.board = $('#' + id);
		
		}

		public add(tagid: string,tagname: string)
		{
			if (this.tags[tagid] != undefined) return;

			var thethis = this;

			//tạo button cancel
			var cancel = $("<span>", {
				id: 'cancel01696_' + tagid,
				class: "icon-cross removebutton"
			});
			cancel.attr("data-userid", tagid);
			cancel['tid'] = tagid;

			cancel.bind('click', function (data)
			{
				thethis.onTagRemove({ id: $(this).attr("data-userid") });
			});

			// tạo một tag mới trong board
			var item = $("<span>", {
				id: '01696_' + tagid,
				text: tagname,
				class: this.classname
			});
			item.append(cancel);
			item['tid'] = tagid;
			item['cancel'] = cancel;
			//item.bind('mouseover', function ()
			//{
			//	var item = $(this);
			//	var cancel = item.find('#cancel' + item[0].id);
			//	cancel.removeClass('hide');
			//});

			//item.bind('mouseleave', function ()
			//{
			//	var item = $(this);
			//	var cancel = item.find('#cancel' + item[0].id);
			//	cancel.addClass('hide');
			//});

			this.board.append(item);
			this.tags[tagid] = item;
		}

		public remove(tagid: string)
		{
		
			if (this.tags[tagid] == undefined)
			{
				console.log(tagid,'should not get in here');
				return;
			}
	
			 this.tags[tagid].remove();this.tags[tagid] = undefined;
		}
	}

}
